package org.jivesoftware.smackx.commands;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.packet.XMPPError.Condition;
import org.jivesoftware.smackx.NodeInformationProvider;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.packet.AdHocCommandData;
import org.jivesoftware.smackx.packet.AdHocCommandData.SpecificError;
import org.jivesoftware.smackx.packet.DiscoverInfo.Identity;
import org.jivesoftware.smackx.packet.DiscoverItems;
import org.jivesoftware.smackx.packet.DiscoverItems.Item;

public class AdHocCommandManager
{
  private static final String DISCO_NAMESPACE = "http://jabber.org/protocol/commands";
  private static final int SESSION_TIMEOUT = 120;
  private static final String discoNode = "http://jabber.org/protocol/commands";
  private static Map<Connection, AdHocCommandManager> instances = new ConcurrentHashMap();
  private Map<String, AdHocCommandInfo> commands = new ConcurrentHashMap();
  private Connection connection;
  private Map<String, LocalCommand> executingCommands = new ConcurrentHashMap();
  private Thread sessionsSweeper;

  static
  {
    Connection.addConnectionCreationListener(new ConnectionCreationListener()
    {
      public void connectionCreated()
      {
        new AdHocCommandManager(paramConnection, null);
      }
    });
  }

  private AdHocCommandManager(Connection paramConnection)
  {
    this.connection = paramConnection;
    init();
  }

  public static AdHocCommandManager getAddHocCommandsManager(Connection paramConnection)
  {
    return ((AdHocCommandManager)instances.get(paramConnection));
  }

  private Collection<AdHocCommandInfo> getRegisteredCommands()
  {
    return this.commands.values();
  }

  private void init()
  {
    instances.put(this.connection, this);
    this.connection.addConnectionListener(new ConnectionListener(this)
    {
      public void connectionClosed()
      {
        AdHocCommandManager.access$1().remove(AdHocCommandManager.access$2(this.this$0));
      }

      public void connectionClosedOnError()
      {
        AdHocCommandManager.access$1().remove(AdHocCommandManager.access$2(this.this$0));
      }

      public void reconnectingIn()
      {
      }

      public void reconnectionFailed()
      {
      }

      public void reconnectionSuccessful()
      {
        AdHocCommandManager.access$1().put(AdHocCommandManager.access$2(this.this$0), this.this$0);
      }
    });
    ServiceDiscoveryManager.getInstanceFor(this.connection).addFeature("http://jabber.org/protocol/commands");
    ServiceDiscoveryManager.getInstanceFor(this.connection).setNodeInformationProvider("http://jabber.org/protocol/commands", new NodeInformationProvider(this)
    {
      public List<String> getNodeFeatures()
      {
        return null;
      }

      public List<DiscoverInfo.Identity> getNodeIdentities()
      {
        return null;
      }

      public List<DiscoverItems.Item> getNodeItems()
      {
        ArrayList localArrayList = new ArrayList();
        Iterator localIterator = AdHocCommandManager.access$3(this.this$0).iterator();
        while (true)
        {
          if (!(localIterator.hasNext()))
            return localArrayList;
          AdHocCommandManager.AdHocCommandInfo localAdHocCommandInfo = (AdHocCommandManager.AdHocCommandInfo)localIterator.next();
          DiscoverItems.Item localItem = new DiscoverItems.Item(localAdHocCommandInfo.getOwnerJID());
          localItem.setName(localAdHocCommandInfo.getName());
          localItem.setNode(localAdHocCommandInfo.getNode());
          localArrayList.add(localItem);
        }
      }
    });
    6 local6 = new PacketListener(this)
    {
      public void processPacket()
      {
        AdHocCommandData localAdHocCommandData = (AdHocCommandData)paramPacket;
        AdHocCommandManager.access$4(this.this$0, localAdHocCommandData);
      }
    };
    PacketTypeFilter localPacketTypeFilter = new PacketTypeFilter(AdHocCommandData.class);
    this.connection.addPacketListener(local6, localPacketTypeFilter);
    this.sessionsSweeper = new Thread(new Runnable(this)
    {
      public void run()
      {
        label0: Iterator localIterator = AdHocCommandManager.access$5(this.this$0).keySet().iterator();
        if (!(localIterator.hasNext()));
        try
        {
          Thread.sleep(1000L);
        }
        catch (InterruptedException localInterruptedException)
        {
          String str;
          long l;
          do
          {
            LocalCommand localLocalCommand;
            do
            {
              break label0:
              str = (String)localIterator.next();
              localLocalCommand = (LocalCommand)AdHocCommandManager.access$5(this.this$0).get(str);
            }
            while (localLocalCommand == null);
            l = localLocalCommand.getCreationDate();
          }
          while (System.currentTimeMillis() - l <= 240000L);
          AdHocCommandManager.access$5(this.this$0).remove(str);
        }
      }
    });
    this.sessionsSweeper.setDaemon(true);
  }

  private LocalCommand newInstanceOfCmd(String paramString1, String paramString2)
    throws XMPPException
  {
    AdHocCommandInfo localAdHocCommandInfo = (AdHocCommandInfo)this.commands.get(paramString1);
    try
    {
      LocalCommand localLocalCommand = localAdHocCommandInfo.getCommandInstance();
      localLocalCommand.setSessionID(paramString2);
      localLocalCommand.setName(localAdHocCommandInfo.getName());
      localLocalCommand.setNode(localAdHocCommandInfo.getNode());
      return localLocalCommand;
    }
    catch (InstantiationException localInstantiationException)
    {
      localInstantiationException.printStackTrace();
      throw new XMPPException(new XMPPError(XMPPError.Condition.interna_server_error));
    }
    catch (IllegalAccessException localIllegalAccessException)
    {
      localIllegalAccessException.printStackTrace();
      throw new XMPPException(new XMPPError(XMPPError.Condition.interna_server_error));
    }
  }

  // ERROR //
  private void processAdHocCommand(AdHocCommandData paramAdHocCommandData)
  {
    // Byte code:
    //   0: aload_1
    //   1: invokevirtual 201	org/jivesoftware/smackx/packet/AdHocCommandData:getType	()Lorg/jivesoftware/smack/packet/IQ$Type;
    //   4: getstatic 207	org/jivesoftware/smack/packet/IQ$Type:SET	Lorg/jivesoftware/smack/packet/IQ$Type;
    //   7: if_acmpeq +4 -> 11
    //   10: return
    //   11: new 130	org/jivesoftware/smackx/packet/AdHocCommandData
    //   14: dup
    //   15: invokespecial 208	org/jivesoftware/smackx/packet/AdHocCommandData:<init>	()V
    //   18: astore_2
    //   19: aload_2
    //   20: aload_1
    //   21: invokevirtual 211	org/jivesoftware/smackx/packet/AdHocCommandData:getFrom	()Ljava/lang/String;
    //   24: invokevirtual 214	org/jivesoftware/smackx/packet/AdHocCommandData:setTo	(Ljava/lang/String;)V
    //   27: aload_2
    //   28: aload_1
    //   29: invokevirtual 217	org/jivesoftware/smackx/packet/AdHocCommandData:getPacketID	()Ljava/lang/String;
    //   32: invokevirtual 220	org/jivesoftware/smackx/packet/AdHocCommandData:setPacketID	(Ljava/lang/String;)V
    //   35: aload_2
    //   36: aload_1
    //   37: invokevirtual 221	org/jivesoftware/smackx/packet/AdHocCommandData:getNode	()Ljava/lang/String;
    //   40: invokevirtual 222	org/jivesoftware/smackx/packet/AdHocCommandData:setNode	(Ljava/lang/String;)V
    //   43: aload_2
    //   44: aload_1
    //   45: invokevirtual 225	org/jivesoftware/smackx/packet/AdHocCommandData:getTo	()Ljava/lang/String;
    //   48: invokevirtual 228	org/jivesoftware/smackx/packet/AdHocCommandData:setId	(Ljava/lang/String;)V
    //   51: aload_1
    //   52: invokevirtual 231	org/jivesoftware/smackx/packet/AdHocCommandData:getSessionID	()Ljava/lang/String;
    //   55: astore_3
    //   56: aload_1
    //   57: invokevirtual 221	org/jivesoftware/smackx/packet/AdHocCommandData:getNode	()Ljava/lang/String;
    //   60: astore 4
    //   62: aload_3
    //   63: ifnonnull +281 -> 344
    //   66: aload_0
    //   67: getfield 60	org/jivesoftware/smackx/commands/AdHocCommandManager:commands	Ljava/util/Map;
    //   70: aload 4
    //   72: invokeinterface 235 2 0
    //   77: ifne +14 -> 91
    //   80: aload_0
    //   81: aload_2
    //   82: getstatic 238	org/jivesoftware/smack/packet/XMPPError$Condition:item_not_found	Lorg/jivesoftware/smack/packet/XMPPError$Condition;
    //   85: invokespecial 242	org/jivesoftware/smackx/commands/AdHocCommandManager:respondError	(Lorg/jivesoftware/smackx/packet/AdHocCommandData;Lorg/jivesoftware/smack/packet/XMPPError$Condition;)V
    //   88: goto -78 -> 10
    //   91: bipush 15
    //   93: invokestatic 248	org/jivesoftware/smack/util/StringUtils:randomString	(I)Ljava/lang/String;
    //   96: astore 16
    //   98: aload_0
    //   99: aload 4
    //   101: aload 16
    //   103: invokespecial 250	org/jivesoftware/smackx/commands/AdHocCommandManager:newInstanceOfCmd	(Ljava/lang/String;Ljava/lang/String;)Lorg/jivesoftware/smackx/commands/LocalCommand;
    //   106: astore 20
    //   108: aload_2
    //   109: getstatic 253	org/jivesoftware/smack/packet/IQ$Type:RESULT	Lorg/jivesoftware/smack/packet/IQ$Type;
    //   112: invokevirtual 257	org/jivesoftware/smackx/packet/AdHocCommandData:setType	(Lorg/jivesoftware/smack/packet/IQ$Type;)V
    //   115: aload 20
    //   117: aload_2
    //   118: invokevirtual 260	org/jivesoftware/smackx/commands/LocalCommand:setData	(Lorg/jivesoftware/smackx/packet/AdHocCommandData;)V
    //   121: aload 20
    //   123: aload_1
    //   124: invokevirtual 211	org/jivesoftware/smackx/packet/AdHocCommandData:getFrom	()Ljava/lang/String;
    //   127: invokevirtual 264	org/jivesoftware/smackx/commands/LocalCommand:hasPermission	(Ljava/lang/String;)Z
    //   130: ifne +71 -> 201
    //   133: aload_0
    //   134: aload_2
    //   135: getstatic 267	org/jivesoftware/smack/packet/XMPPError$Condition:forbidden	Lorg/jivesoftware/smack/packet/XMPPError$Condition;
    //   138: invokespecial 242	org/jivesoftware/smackx/commands/AdHocCommandManager:respondError	(Lorg/jivesoftware/smackx/packet/AdHocCommandData;Lorg/jivesoftware/smack/packet/XMPPError$Condition;)V
    //   141: goto -131 -> 10
    //   144: astore 17
    //   146: aload 17
    //   148: invokevirtual 271	XMPPException:getXMPPError	()Lorg/jivesoftware/smack/packet/XMPPError;
    //   151: astore 18
    //   153: getstatic 277	org/jivesoftware/smack/packet/XMPPError$Type:CANCEL	Lorg/jivesoftware/smack/packet/XMPPError$Type;
    //   156: aload 18
    //   158: invokevirtual 280	org/jivesoftware/smack/packet/XMPPError:getType	()Lorg/jivesoftware/smack/packet/XMPPError$Type;
    //   161: invokevirtual 283	org/jivesoftware/smack/packet/XMPPError$Type:equals	(Ljava/lang/Object;)Z
    //   164: ifeq +22 -> 186
    //   167: aload_2
    //   168: getstatic 289	org/jivesoftware/smackx/commands/AdHocCommand$Status:canceled	Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;
    //   171: invokevirtual 293	org/jivesoftware/smackx/packet/AdHocCommandData:setStatus	(Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;)V
    //   174: aload_0
    //   175: getfield 62	org/jivesoftware/smackx/commands/AdHocCommandManager:executingCommands	Ljava/util/Map;
    //   178: aload 16
    //   180: invokeinterface 296 2 0
    //   185: pop
    //   186: aload_0
    //   187: aload_2
    //   188: aload 18
    //   190: invokespecial 299	org/jivesoftware/smackx/commands/AdHocCommandManager:respondError	(Lorg/jivesoftware/smackx/packet/AdHocCommandData;Lorg/jivesoftware/smack/packet/XMPPError;)V
    //   193: aload 17
    //   195: invokevirtual 300	XMPPException:printStackTrace	()V
    //   198: goto -188 -> 10
    //   201: aload_1
    //   202: invokevirtual 304	org/jivesoftware/smackx/packet/AdHocCommandData:getAction	()Lorg/jivesoftware/smackx/commands/AdHocCommand$Action;
    //   205: astore 21
    //   207: aload 21
    //   209: ifnull +28 -> 237
    //   212: aload 21
    //   214: getstatic 310	org/jivesoftware/smackx/commands/AdHocCommand$Action:unknown	Lorg/jivesoftware/smackx/commands/AdHocCommand$Action;
    //   217: invokevirtual 311	org/jivesoftware/smackx/commands/AdHocCommand$Action:equals	(Ljava/lang/Object;)Z
    //   220: ifeq +17 -> 237
    //   223: aload_0
    //   224: aload_2
    //   225: getstatic 314	org/jivesoftware/smack/packet/XMPPError$Condition:bad_request	Lorg/jivesoftware/smack/packet/XMPPError$Condition;
    //   228: getstatic 320	org/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition:malformedAction	Lorg/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition;
    //   231: invokespecial 323	org/jivesoftware/smackx/commands/AdHocCommandManager:respondError	(Lorg/jivesoftware/smackx/packet/AdHocCommandData;Lorg/jivesoftware/smack/packet/XMPPError$Condition;Lorg/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition;)V
    //   234: goto -224 -> 10
    //   237: aload 21
    //   239: ifnull +28 -> 267
    //   242: aload 21
    //   244: getstatic 326	org/jivesoftware/smackx/commands/AdHocCommand$Action:execute	Lorg/jivesoftware/smackx/commands/AdHocCommand$Action;
    //   247: invokevirtual 311	org/jivesoftware/smackx/commands/AdHocCommand$Action:equals	(Ljava/lang/Object;)Z
    //   250: ifne +17 -> 267
    //   253: aload_0
    //   254: aload_2
    //   255: getstatic 314	org/jivesoftware/smack/packet/XMPPError$Condition:bad_request	Lorg/jivesoftware/smack/packet/XMPPError$Condition;
    //   258: getstatic 329	org/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition:badAction	Lorg/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition;
    //   261: invokespecial 323	org/jivesoftware/smackx/commands/AdHocCommandManager:respondError	(Lorg/jivesoftware/smackx/packet/AdHocCommandData;Lorg/jivesoftware/smack/packet/XMPPError$Condition;Lorg/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition;)V
    //   264: goto -254 -> 10
    //   267: aload 20
    //   269: invokevirtual 332	org/jivesoftware/smackx/commands/LocalCommand:incrementStage	()V
    //   272: aload 20
    //   274: invokevirtual 334	org/jivesoftware/smackx/commands/LocalCommand:execute	()V
    //   277: aload 20
    //   279: invokevirtual 338	org/jivesoftware/smackx/commands/LocalCommand:isLastStage	()Z
    //   282: ifeq +21 -> 303
    //   285: aload_2
    //   286: getstatic 341	org/jivesoftware/smackx/commands/AdHocCommand$Status:completed	Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;
    //   289: invokevirtual 293	org/jivesoftware/smackx/packet/AdHocCommandData:setStatus	(Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;)V
    //   292: aload_0
    //   293: getfield 64	org/jivesoftware/smackx/commands/AdHocCommandManager:connection	Lorg/jivesoftware/smack/Connection;
    //   296: aload_2
    //   297: invokevirtual 345	org/jivesoftware/smack/Connection:sendPacket	(Lorg/jivesoftware/smack/packet/Packet;)V
    //   300: goto -290 -> 10
    //   303: aload_2
    //   304: getstatic 348	org/jivesoftware/smackx/commands/AdHocCommand$Status:executing	Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;
    //   307: invokevirtual 293	org/jivesoftware/smackx/packet/AdHocCommandData:setStatus	(Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;)V
    //   310: aload_0
    //   311: getfield 62	org/jivesoftware/smackx/commands/AdHocCommandManager:executingCommands	Ljava/util/Map;
    //   314: aload 16
    //   316: aload 20
    //   318: invokeinterface 103 3 0
    //   323: pop
    //   324: aload_0
    //   325: getfield 145	org/jivesoftware/smackx/commands/AdHocCommandManager:sessionsSweeper	Ljava/lang/Thread;
    //   328: invokevirtual 351	java/lang/Thread:isAlive	()Z
    //   331: ifne -39 -> 292
    //   334: aload_0
    //   335: getfield 145	org/jivesoftware/smackx/commands/AdHocCommandManager:sessionsSweeper	Ljava/lang/Thread;
    //   338: invokevirtual 354	java/lang/Thread:start	()V
    //   341: goto -49 -> 292
    //   344: aload_0
    //   345: getfield 62	org/jivesoftware/smackx/commands/AdHocCommandManager:executingCommands	Ljava/util/Map;
    //   348: aload_3
    //   349: invokeinterface 96 2 0
    //   354: checkcast 163	org/jivesoftware/smackx/commands/LocalCommand
    //   357: astore 5
    //   359: aload 5
    //   361: ifnonnull +17 -> 378
    //   364: aload_0
    //   365: aload_2
    //   366: getstatic 314	org/jivesoftware/smack/packet/XMPPError$Condition:bad_request	Lorg/jivesoftware/smack/packet/XMPPError$Condition;
    //   369: getstatic 357	org/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition:badSessionid	Lorg/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition;
    //   372: invokespecial 323	org/jivesoftware/smackx/commands/AdHocCommandManager:respondError	(Lorg/jivesoftware/smackx/packet/AdHocCommandData;Lorg/jivesoftware/smack/packet/XMPPError$Condition;Lorg/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition;)V
    //   375: goto -365 -> 10
    //   378: aload 5
    //   380: invokevirtual 361	org/jivesoftware/smackx/commands/LocalCommand:getCreationDate	()J
    //   383: lstore 6
    //   385: invokestatic 366	java/lang/System:currentTimeMillis	()J
    //   388: lload 6
    //   390: lsub
    //   391: ldc2_w 367
    //   394: lcmp
    //   395: ifle +28 -> 423
    //   398: aload_0
    //   399: getfield 62	org/jivesoftware/smackx/commands/AdHocCommandManager:executingCommands	Ljava/util/Map;
    //   402: aload_3
    //   403: invokeinterface 296 2 0
    //   408: pop
    //   409: aload_0
    //   410: aload_2
    //   411: getstatic 371	org/jivesoftware/smack/packet/XMPPError$Condition:not_allowed	Lorg/jivesoftware/smack/packet/XMPPError$Condition;
    //   414: getstatic 374	org/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition:sessionExpired	Lorg/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition;
    //   417: invokespecial 323	org/jivesoftware/smackx/commands/AdHocCommandManager:respondError	(Lorg/jivesoftware/smackx/packet/AdHocCommandData;Lorg/jivesoftware/smack/packet/XMPPError$Condition;Lorg/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition;)V
    //   420: goto -410 -> 10
    //   423: aload 5
    //   425: monitorenter
    //   426: aload_1
    //   427: invokevirtual 304	org/jivesoftware/smackx/packet/AdHocCommandData:getAction	()Lorg/jivesoftware/smackx/commands/AdHocCommand$Action;
    //   430: astore 9
    //   432: aload 9
    //   434: ifnull +39 -> 473
    //   437: aload 9
    //   439: getstatic 310	org/jivesoftware/smackx/commands/AdHocCommand$Action:unknown	Lorg/jivesoftware/smackx/commands/AdHocCommand$Action;
    //   442: invokevirtual 311	org/jivesoftware/smackx/commands/AdHocCommand$Action:equals	(Ljava/lang/Object;)Z
    //   445: ifeq +28 -> 473
    //   448: aload_0
    //   449: aload_2
    //   450: getstatic 314	org/jivesoftware/smack/packet/XMPPError$Condition:bad_request	Lorg/jivesoftware/smack/packet/XMPPError$Condition;
    //   453: getstatic 320	org/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition:malformedAction	Lorg/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition;
    //   456: invokespecial 323	org/jivesoftware/smackx/commands/AdHocCommandManager:respondError	(Lorg/jivesoftware/smackx/packet/AdHocCommandData;Lorg/jivesoftware/smack/packet/XMPPError$Condition;Lorg/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition;)V
    //   459: aload 5
    //   461: monitorexit
    //   462: goto -452 -> 10
    //   465: astore 8
    //   467: aload 5
    //   469: monitorexit
    //   470: aload 8
    //   472: athrow
    //   473: aload 9
    //   475: ifnull +14 -> 489
    //   478: getstatic 326	org/jivesoftware/smackx/commands/AdHocCommand$Action:execute	Lorg/jivesoftware/smackx/commands/AdHocCommand$Action;
    //   481: aload 9
    //   483: invokevirtual 311	org/jivesoftware/smackx/commands/AdHocCommand$Action:equals	(Ljava/lang/Object;)Z
    //   486: ifeq +10 -> 496
    //   489: aload 5
    //   491: invokevirtual 377	org/jivesoftware/smackx/commands/LocalCommand:getExecuteAction	()Lorg/jivesoftware/smackx/commands/AdHocCommand$Action;
    //   494: astore 9
    //   496: aload 5
    //   498: aload 9
    //   500: invokevirtual 381	org/jivesoftware/smackx/commands/LocalCommand:isValidAction	(Lorg/jivesoftware/smackx/commands/AdHocCommand$Action;)Z
    //   503: ifne +20 -> 523
    //   506: aload_0
    //   507: aload_2
    //   508: getstatic 314	org/jivesoftware/smack/packet/XMPPError$Condition:bad_request	Lorg/jivesoftware/smack/packet/XMPPError$Condition;
    //   511: getstatic 329	org/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition:badAction	Lorg/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition;
    //   514: invokespecial 323	org/jivesoftware/smackx/commands/AdHocCommandManager:respondError	(Lorg/jivesoftware/smackx/packet/AdHocCommandData;Lorg/jivesoftware/smack/packet/XMPPError$Condition;Lorg/jivesoftware/smackx/commands/AdHocCommand$SpecificErrorCondition;)V
    //   517: aload 5
    //   519: monitorexit
    //   520: goto -510 -> 10
    //   523: aload_2
    //   524: getstatic 253	org/jivesoftware/smack/packet/IQ$Type:RESULT	Lorg/jivesoftware/smack/packet/IQ$Type;
    //   527: invokevirtual 257	org/jivesoftware/smackx/packet/AdHocCommandData:setType	(Lorg/jivesoftware/smack/packet/IQ$Type;)V
    //   530: aload 5
    //   532: aload_2
    //   533: invokevirtual 260	org/jivesoftware/smackx/commands/LocalCommand:setData	(Lorg/jivesoftware/smackx/packet/AdHocCommandData;)V
    //   536: getstatic 384	org/jivesoftware/smackx/commands/AdHocCommand$Action:next	Lorg/jivesoftware/smackx/commands/AdHocCommand$Action;
    //   539: aload 9
    //   541: invokevirtual 311	org/jivesoftware/smackx/commands/AdHocCommand$Action:equals	(Ljava/lang/Object;)Z
    //   544: ifeq +119 -> 663
    //   547: aload 5
    //   549: invokevirtual 332	org/jivesoftware/smackx/commands/LocalCommand:incrementStage	()V
    //   552: aload 5
    //   554: new 386	org/jivesoftware/smackx/Form
    //   557: dup
    //   558: aload_1
    //   559: invokevirtual 390	org/jivesoftware/smackx/packet/AdHocCommandData:getForm	()Lorg/jivesoftware/smackx/packet/DataForm;
    //   562: invokespecial 393	org/jivesoftware/smackx/Form:<init>	(Lorg/jivesoftware/smackx/packet/DataForm;)V
    //   565: invokevirtual 396	org/jivesoftware/smackx/commands/LocalCommand:next	(Lorg/jivesoftware/smackx/Form;)V
    //   568: aload 5
    //   570: invokevirtual 338	org/jivesoftware/smackx/commands/LocalCommand:isLastStage	()Z
    //   573: ifeq +24 -> 597
    //   576: aload_2
    //   577: getstatic 341	org/jivesoftware/smackx/commands/AdHocCommand$Status:completed	Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;
    //   580: invokevirtual 293	org/jivesoftware/smackx/packet/AdHocCommandData:setStatus	(Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;)V
    //   583: aload_0
    //   584: getfield 64	org/jivesoftware/smackx/commands/AdHocCommandManager:connection	Lorg/jivesoftware/smack/Connection;
    //   587: aload_2
    //   588: invokevirtual 345	org/jivesoftware/smack/Connection:sendPacket	(Lorg/jivesoftware/smack/packet/Packet;)V
    //   591: aload 5
    //   593: monitorexit
    //   594: goto -584 -> 10
    //   597: aload_2
    //   598: getstatic 348	org/jivesoftware/smackx/commands/AdHocCommand$Status:executing	Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;
    //   601: invokevirtual 293	org/jivesoftware/smackx/packet/AdHocCommandData:setStatus	(Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;)V
    //   604: goto -21 -> 583
    //   607: astore 10
    //   609: aload 10
    //   611: invokevirtual 271	XMPPException:getXMPPError	()Lorg/jivesoftware/smack/packet/XMPPError;
    //   614: astore 11
    //   616: getstatic 277	org/jivesoftware/smack/packet/XMPPError$Type:CANCEL	Lorg/jivesoftware/smack/packet/XMPPError$Type;
    //   619: aload 11
    //   621: invokevirtual 280	org/jivesoftware/smack/packet/XMPPError:getType	()Lorg/jivesoftware/smack/packet/XMPPError$Type;
    //   624: invokevirtual 283	org/jivesoftware/smack/packet/XMPPError$Type:equals	(Ljava/lang/Object;)Z
    //   627: ifeq +21 -> 648
    //   630: aload_2
    //   631: getstatic 289	org/jivesoftware/smackx/commands/AdHocCommand$Status:canceled	Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;
    //   634: invokevirtual 293	org/jivesoftware/smackx/packet/AdHocCommandData:setStatus	(Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;)V
    //   637: aload_0
    //   638: getfield 62	org/jivesoftware/smackx/commands/AdHocCommandManager:executingCommands	Ljava/util/Map;
    //   641: aload_3
    //   642: invokeinterface 296 2 0
    //   647: pop
    //   648: aload_0
    //   649: aload_2
    //   650: aload 11
    //   652: invokespecial 299	org/jivesoftware/smackx/commands/AdHocCommandManager:respondError	(Lorg/jivesoftware/smackx/packet/AdHocCommandData;Lorg/jivesoftware/smack/packet/XMPPError;)V
    //   655: aload 10
    //   657: invokevirtual 300	XMPPException:printStackTrace	()V
    //   660: goto -69 -> 591
    //   663: getstatic 399	org/jivesoftware/smackx/commands/AdHocCommand$Action:complete	Lorg/jivesoftware/smackx/commands/AdHocCommand$Action;
    //   666: aload 9
    //   668: invokevirtual 311	org/jivesoftware/smackx/commands/AdHocCommand$Action:equals	(Ljava/lang/Object;)Z
    //   671: ifeq +45 -> 716
    //   674: aload 5
    //   676: invokevirtual 332	org/jivesoftware/smackx/commands/LocalCommand:incrementStage	()V
    //   679: aload 5
    //   681: new 386	org/jivesoftware/smackx/Form
    //   684: dup
    //   685: aload_1
    //   686: invokevirtual 390	org/jivesoftware/smackx/packet/AdHocCommandData:getForm	()Lorg/jivesoftware/smackx/packet/DataForm;
    //   689: invokespecial 393	org/jivesoftware/smackx/Form:<init>	(Lorg/jivesoftware/smackx/packet/DataForm;)V
    //   692: invokevirtual 401	org/jivesoftware/smackx/commands/LocalCommand:complete	(Lorg/jivesoftware/smackx/Form;)V
    //   695: aload_2
    //   696: getstatic 341	org/jivesoftware/smackx/commands/AdHocCommand$Status:completed	Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;
    //   699: invokevirtual 293	org/jivesoftware/smackx/packet/AdHocCommandData:setStatus	(Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;)V
    //   702: aload_0
    //   703: getfield 62	org/jivesoftware/smackx/commands/AdHocCommandManager:executingCommands	Ljava/util/Map;
    //   706: aload_3
    //   707: invokeinterface 296 2 0
    //   712: pop
    //   713: goto -130 -> 583
    //   716: getstatic 404	org/jivesoftware/smackx/commands/AdHocCommand$Action:prev	Lorg/jivesoftware/smackx/commands/AdHocCommand$Action;
    //   719: aload 9
    //   721: invokevirtual 311	org/jivesoftware/smackx/commands/AdHocCommand$Action:equals	(Ljava/lang/Object;)Z
    //   724: ifeq +16 -> 740
    //   727: aload 5
    //   729: invokevirtual 407	org/jivesoftware/smackx/commands/LocalCommand:decrementStage	()V
    //   732: aload 5
    //   734: invokevirtual 409	org/jivesoftware/smackx/commands/LocalCommand:prev	()V
    //   737: goto -154 -> 583
    //   740: getstatic 412	org/jivesoftware/smackx/commands/AdHocCommand$Action:cancel	Lorg/jivesoftware/smackx/commands/AdHocCommand$Action;
    //   743: aload 9
    //   745: invokevirtual 311	org/jivesoftware/smackx/commands/AdHocCommand$Action:equals	(Ljava/lang/Object;)Z
    //   748: ifeq -165 -> 583
    //   751: aload 5
    //   753: invokevirtual 414	org/jivesoftware/smackx/commands/LocalCommand:cancel	()V
    //   756: aload_2
    //   757: getstatic 289	org/jivesoftware/smackx/commands/AdHocCommand$Status:canceled	Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;
    //   760: invokevirtual 293	org/jivesoftware/smackx/packet/AdHocCommandData:setStatus	(Lorg/jivesoftware/smackx/commands/AdHocCommand$Status;)V
    //   763: aload_0
    //   764: getfield 62	org/jivesoftware/smackx/commands/AdHocCommandManager:executingCommands	Ljava/util/Map;
    //   767: aload_3
    //   768: invokeinterface 296 2 0
    //   773: pop
    //   774: goto -191 -> 583
    //
    // Exception table:
    //   from	to	target	type
    //   98	141	144	XMPPException
    //   201	341	144	XMPPException
    //   426	470	465	finally
    //   478	520	465	finally
    //   523	591	465	finally
    //   591	594	465	finally
    //   597	604	465	finally
    //   609	660	465	finally
    //   663	774	465	finally
    //   523	591	607	XMPPException
    //   597	604	607	XMPPException
    //   663	774	607	XMPPException
  }

  private void respondError(AdHocCommandData paramAdHocCommandData, XMPPError.Condition paramCondition)
  {
    respondError(paramAdHocCommandData, new XMPPError(paramCondition));
  }

  private void respondError(AdHocCommandData paramAdHocCommandData, XMPPError.Condition paramCondition, AdHocCommand.SpecificErrorCondition paramSpecificErrorCondition)
  {
    XMPPError localXMPPError = new XMPPError(paramCondition);
    localXMPPError.addExtension(new AdHocCommandData.SpecificError(paramSpecificErrorCondition));
    respondError(paramAdHocCommandData, localXMPPError);
  }

  private void respondError(AdHocCommandData paramAdHocCommandData, XMPPError paramXMPPError)
  {
    paramAdHocCommandData.setType(IQ.Type.ERROR);
    paramAdHocCommandData.setError(paramXMPPError);
    this.connection.sendPacket(paramAdHocCommandData);
  }

  public DiscoverItems discoverCommands(String paramString)
    throws XMPPException
  {
    return ServiceDiscoveryManager.getInstanceFor(this.connection).discoverItems(paramString, "http://jabber.org/protocol/commands");
  }

  public RemoteCommand getRemoteCommand(String paramString1, String paramString2)
  {
    return new RemoteCommand(this.connection, paramString2, paramString1);
  }

  public void publishCommands(String paramString)
    throws XMPPException
  {
    ServiceDiscoveryManager localServiceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.connection);
    DiscoverItems localDiscoverItems = new DiscoverItems();
    Iterator localIterator = getRegisteredCommands().iterator();
    while (true)
    {
      if (!(localIterator.hasNext()))
      {
        localServiceDiscoveryManager.publishItems(paramString, "http://jabber.org/protocol/commands", localDiscoverItems);
        return;
      }
      AdHocCommandInfo localAdHocCommandInfo = (AdHocCommandInfo)localIterator.next();
      DiscoverItems.Item localItem = new DiscoverItems.Item(localAdHocCommandInfo.getOwnerJID());
      localItem.setName(localAdHocCommandInfo.getName());
      localItem.setNode(localAdHocCommandInfo.getNode());
      localDiscoverItems.addItem(localItem);
    }
  }

  public void registerCommand(String paramString1, String paramString2, Class paramClass)
  {
    registerCommand(paramString1, paramString2, new LocalCommandFactory(this, paramClass)
    {
      public LocalCommand getInstance()
        throws InstantiationException, IllegalAccessException
      {
        return ((LocalCommand)this.val$clazz.newInstance());
      }
    });
  }

  public void registerCommand(String paramString1, String paramString2, LocalCommandFactory paramLocalCommandFactory)
  {
    AdHocCommandInfo localAdHocCommandInfo = new AdHocCommandInfo(paramString1, paramString2, this.connection.getUser(), paramLocalCommandFactory);
    this.commands.put(paramString1, localAdHocCommandInfo);
    ServiceDiscoveryManager.getInstanceFor(this.connection).setNodeInformationProvider(paramString1, new NodeInformationProvider(this, paramString2)
    {
      public List<String> getNodeFeatures()
      {
        ArrayList localArrayList = new ArrayList();
        localArrayList.add("http://jabber.org/protocol/commands");
        localArrayList.add("jabber:x:data");
        return localArrayList;
      }

      public List<DiscoverInfo.Identity> getNodeIdentities()
      {
        ArrayList localArrayList = new ArrayList();
        DiscoverInfo.Identity localIdentity = new DiscoverInfo.Identity("automation", this.val$name);
        localIdentity.setType("command-node");
        localArrayList.add(localIdentity);
        return localArrayList;
      }

      public List<DiscoverItems.Item> getNodeItems()
      {
        return null;
      }
    });
  }

  private static class AdHocCommandInfo
  {
    private LocalCommandFactory factory;
    private String name;
    private String node;
    private String ownerJID;

    public AdHocCommandInfo(String paramString1, String paramString2, String paramString3, LocalCommandFactory paramLocalCommandFactory)
    {
      this.node = paramString1;
      this.name = paramString2;
      this.ownerJID = paramString3;
      this.factory = paramLocalCommandFactory;
    }

    public LocalCommand getCommandInstance()
      throws InstantiationException, IllegalAccessException
    {
      return this.factory.getInstance();
    }

    public String getName()
    {
      return this.name;
    }

    public String getNode()
    {
      return this.node;
    }

    public String getOwnerJID()
    {
      return this.ownerJID;
    }
  }
}